package com.macaline.framemarker.dataBase.mysql.enums;

import java.util.Arrays;

/**
 * 数据库字段类型
 */
public enum ColumnType {

    INT(1, "int", "int类型"),
    CHAR(2, "char", "char类型"),
    VARCHAR(4, "varchar", "varchar类型"),
    DOUBLE(3, "int", "double类型");

    ColumnType(Integer code, String typeName, String annotation) {
        this.code = code;
        this.typeName = typeName;
        this.annotation = annotation;
    }

    /**
     * 通过code获取数据库中对应的类型名
     * @param code 编码
     * @return
     */
    public static String getTypeNameByCode(Integer code){
        ColumnType[] values = ColumnType.values();
        ColumnType result = Arrays.asList(values).stream()
                .filter(alarmGrade -> alarmGrade.code.equals(code))
                .findFirst().orElse(null);
        if(result == null){
            return null;
        }
        return result.getTypeName();
    }

    private Integer code; // 系统内规定标识
    private String typeName; // 数据库类型
    private String annotation; // 注释

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getAnnotation() {
        return annotation;
    }

    public void setAnnotation(String annotation) {
        this.annotation = annotation;
    }
}
